<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        //对象的常用方法
        var obj = { name: '写', age: 26, job: '学生' }
        //键值对{key:value}
        console.log(Object.keys(obj))
        console.log(Object.values(obj))
        console.log(Object.entries(obj))
        //[['name','写']]={name:'xie'}
        const a = new Map([['name', '写']])
        const b = Object.fromEntries(a)
        console.log(b)

        //数组方法
        var arr = [1, 2, 3, 4, 5, 6]
        // 过滤 filte返回值:数组
        console.log(arr.filter(i => {
            return i > 4
        }))
        // 查找 find findIndex some includes
        console.log(arr.find(i => i > 4))
        //找下标
        console.log(arr.findIndex(i => i === 4))
        console.log(arr.some(i => /\d/.test(i)))
        console.log(arr.includes(7)) //返回布尔
        // 遍历 map仅仅是遍历,不会修改原始数组
        arr.map(value => {
            return value
        })
        // 累计计算
        var Arr = [{
            name: '苹果',
            $: 100,
            n: 5
        }, {
            name: '苹果',
            $: 80,
            n: 3
        }, {
            name: '苹果',
            $: 10,
            n: 1
        },]
        const result = Arr.reduce((a, b) => {
            return a + b.n * b.$
        }, 0)
        console.log(result)
        // 排序
        var arr3 = [{age:6}, {age:16}, {age:10}]
        var arr4 = ['王','李','送']
        var a1 = arr3.sort((a, b) => {
            // 比较运算符
            return a.age - b.age
        })
        console.log(a1)
        // 扁平化
        var arr5 = [[100],[55],[66,[99]],[22,[11,[10]]]]
        //flat(number) 
        var newArr = arr5.flat(Infinity)
        console.log(Array.from(new Set(newArr)))
        
    </script>
</body>

</html>